#include "key.h"

void boot_key_init(void)
{
    gpio_config_t boot_init_stuct={0};
    boot_init_stuct.pin_bit_mask = 1ULL << BOOT_GPIO_PIN;
    boot_init_stuct.mode = GPIO_MODE_INPUT;
    boot_init_stuct.intr_type = GPIO_INTR_DISABLE;
    boot_init_stuct.pull_up_en = GPIO_PULLUP_ENABLE;
    boot_init_stuct.pull_down_en = GPIO_PULLDOWN_DISABLE;
    gpio_config(&boot_init_stuct);
}

uint8_t boot_scan(uint8_t mode)
{
    uint8_t key_value = BOOT_KEY_LIFT;
    static uint8_t key_pres = BOOT_KEY_LIFT;

    if (mode == 1)
    {
        key_pres = BOOT_KEY_LIFT;
    }

    if (BOOT_KEY_VALUE == BOOT_KEY_PRES)
    {
        vTaskDelay(pdMS_TO_TICKS(10));
        if (BOOT_KEY_VALUE == BOOT_KEY_PRES &&
            key_pres == BOOT_KEY_LIFT)
        {
            key_value = BOOT_KEY_PRES;
            key_pres = BOOT_KEY_PRES;
        }
    }
    else
    {
        key_pres = BOOT_KEY_LIFT;
    }
    return key_value;
}
